var path = require('path')
var resovle = function (dir) {
  return path.join(__dirname, '..', dir)
}
var webpack = require('webpack')
var UglifyJSPlugin = require('uglifyjs-webpack-plugin')
const ExtractTextPlugin = require("extract-text-webpack-plugin")
const staticPort = require('./configs/local.json')
console.log(resovle('src/dao'))

console.log(process.env.NODE_ENV)

module.exports = {
  entry: {
    app: ["babel-polyfill",'./src/main.js']         // babel-polyfill 兼容IE
  },
  output: {
    path: resovle('ygy-cli/build'),
    publicPath: '/static/',
    filename: 'build.js'
  },
  resolve: {
    alias: {
      'vue': 'vue/dist/vue.js',
      'dao': resovle('ygy-cli/src/dao'),
      'src': resovle('ygy-cli/src')
    }
  },
  module: {
    loaders: [{
      test: /\.vue$/,
      loader: 'vue-loader'
    },{
      test: /\.js$/,
      loader: 'babel-loader'
    },{
      test: /\.css$/,
      loader: 'style-loader!css-loader'
    },
    {
      test: /\.scss$/,
      loader: 'style-loader!css-loader!saa-loader'
    }]
  }
}

if (process.env.NODE_ENV === 'production') {
  module.exports.plugins = [
    new ExtractTextPlugin({
      filename: 'css/[name].css',
      allChunks: false
    }),
    new webpack.DefinePlugin({               // 定义在业务中可以访问到的变量
      NODE_ENV: '"production"'       
    }),
    new webpack.optimize.UglifyJsPlugin({
      comments: false,
      compress: {
        warnings: false
      }
    })
  ]
} else if (process.env.NODE_ENV === 'dev') {
  module.exports.devServer = {              // 端口号
    port: staticPort.dev.staticPort
  }
  module.exports.plugins = [
    new webpack.DefinePlugin({              // 定义在业务中可以访问到的变量
      NODE_ENV: '"dev"'       
    })
  ]
  module.exports.devtool = '#cheap-module-eval-source-map' // 开发环境报错
}